/**
 * Created by duanxiancai on 2017/1/10.
 */
window.onerror = function(err) {
    console.log(err);
}
//注册事件监听
function connectWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) {
        callback(WebViewJavascriptBridge)
    } else {
        document.addEventListener(
            'WebViewJavascriptBridgeReady'
            , function() {
                callback(WebViewJavascriptBridge)
            },
            false
        );
    }
}
function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    else if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    else {
        document.addEventListener('WebViewJavascriptBridgeReady', function() {
            callback(WebViewJavascriptBridge)
        },false);}
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'https://__bridge_loaded__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
function indexBridgeInit(client,callback) {
    setupWebViewJavascriptBridge(function(bridge) {
        if (client == 'android'){
            bridge.init(function(message, responseCallback) {
                responseCallback(responseData);
            });
        }
        callback(bridge);
    });
}

